using UnityEngine;

public class LiquidIllumination : MonoBehaviour
{
	public enum IlluminationLevel
	{
		Brighter,
		Brightest
	}

	private SpriteRenderer spriteRenderer;

	private Vector2 spriteSize;

	private Vector3 spritePosition;

	private float initialPosition;

	private float brighterLiquidOffset = 0.3f;

	private float brighterLiquidHeightDifference = 0.7f;

	private float brightestLiquidOffset = 0.45f;

	private float brightestLiquidHeightDifference = 1.2f;

	public IlluminationLevel illuminationLevel;

	private void Awake()
	{
		DefineConnections();
		spriteSize = Vector2.zero;
		spritePosition = base.transform.position;
	}

	private void DefineConnections()
	{
		spriteRenderer = GetComponent<SpriteRenderer>();
	}

	public void InitializeIllumination(float liquidWidth, float liquidPosY)
	{
		spriteSize.x = liquidWidth;
		if (illuminationLevel == IlluminationLevel.Brighter)
		{
			initialPosition = liquidPosY + brighterLiquidOffset;
		}
		else if (illuminationLevel == IlluminationLevel.Brightest)
		{
			initialPosition = liquidPosY + brightestLiquidOffset;
		}
	}

	public void SetIlluminationHeight(float liquidHeight)
	{
		if (illuminationLevel == IlluminationLevel.Brighter)
		{
			spriteSize.y = liquidHeight - brighterLiquidHeightDifference;
			if (spriteSize.y < 0f)
			{
				spriteSize.y = 0f;
			}
		}
		else if (illuminationLevel == IlluminationLevel.Brightest)
		{
			spriteSize.y = liquidHeight - brightestLiquidHeightDifference;
			if (spriteSize.y < 0f)
			{
				spriteSize.y = 0f;
			}
		}
		UpdateSpriteSize();
	}

	public void SetIlluminationLowerEdgePosition(float liquidHeight, float offset)
	{
		UpdateSpritePosition(liquidHeight, offset);
	}

	private void UpdateSpriteSize()
	{
		spriteRenderer.size = spriteSize;
	}

	private void UpdateSpritePosition(float liquidHeight, float offset)
	{
		spritePosition.y = initialPosition + offset + spriteSize.y * 0.5f;
		ref Vector3 reference = ref spritePosition;
		Vector3 position = base.transform.position;
		reference.x = position.x;
		ref Vector3 reference2 = ref spritePosition;
		Vector3 position2 = base.transform.position;
		reference2.z = position2.z;
		base.transform.position = spritePosition;
	}

	public void SetIlluminationColor(Color32 color)
	{
		spriteRenderer.color = color;
	}
}
